import {createRouter, createWebHistory, createMemoryHistory} from 'vue-router'
import Index from '../views/Home/Index.vue'

const Login = () => import('../views/Login.vue')

const Home = () => import('../views/Home/Home.vue')
const UserList = () => import('../views/Admin/UserList.vue')
const ErrorLog = () => import('../views/Admin/ErrorLog.vue')
const Column = () => import('../views/Chart/Column.vue')
const Line = () => import('../views/Chart/Line.vue')
const Pie = () => import('../views/Chart/Pie.vue')
const Demo = () => import('../views/Demo/Demo.vue')
const routes = [
    {
        path: '/',
        redirect: 'Login',
        meta: {
            title: "登录",
            intercept: false
        }
    },
    {
        path: '/Login',
        name: 'Login',
        component: Login,
        meta: {
            title: "登录",
            intercept: false
        }
    },
    {
        path: '/Index',
        name: 'Index',
        component: Index,
        redirect: 'Home',
        meta: {
            title: "首页",
            intercept: true
        },
        children: [{
            path: '/Home',
            name: 'Home',
            component: Home,
            meta: {
                title: "主页",
                intercept: true
            },
        }, {
            path: '/UserList',
            name: 'UserList',
            component: UserList,
            meta: {
                title: "用户列表",
                intercept: true
            },
        }, {
            path: '/ErrorLog',
            name: 'ErrorLog',
            component: ErrorLog,
            meta: {
                title: "错误日志",
                intercept: true
            },
        }, {
            path: '/Column',
            name: 'Column',
            component: Column,
            meta: {
                title: "柱状图",
                intercept: true
            },
        }, {
            path: '/Line',
            name: 'Line',
            component: Line,
            meta: {
                title: "折现图",
                intercept: true
            },
        }, {
            path: '/Pie',
            name: 'Pie',
            component: Pie,
            meta: {
                title: "饼图",
                intercept: true
            },
        }, {
            path: '/Demo',
            name: 'Demo',
            component: Demo,
            meta: {
                title: "Demo",
                intercept: false
            }
        },]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    // if (to.meta.intercept) {
    //      alert('请登录')
    // } else
    //     next()
    next()
});


router.afterEach((to, from) => {
    document.title = to.meta.title as string;
})

export default router
